export default {
  data() {
    return {
      schoolList: [],
      deptList: [],
      classList: [],
			schoolCodeNum:0,//学校
    }
  },
  created() {
    this.getSchool()
  },
  methods: {
    onSchoolChange(schoolCode) {
      this.clearSchool()
			this.schoolCodeNum=schoolCode;//存储学校CODE方便后面学院事件改变使用
      if (schoolCode) {
        this.getDept(schoolCode)
        this.updateSchoolCode && this.updateSchoolCode(schoolCode)
      }
    },
    onDeptChange(deptCode) {
      this.clearDept()
			//学院事件改变重新获取
			if(this.schoolCodeNum){
				this.getDept(this.schoolCodeNum)
			}
      if (deptCode) {
        this.getClass(deptCode)
        this.updateDeptCode && this.updateDeptCode(deptCode)
      }
    },
    getSchool() {
      this.api.getSchool().then(res => {
        this.schoolList = res
      })
    },
    getDept(schoolCode) {
      this.axios.get("/sys/class/GetDepartments", {
        params: {
          type: 1,
          pcode: schoolCode
        }
      })
        .then(res => {
          this.deptList.splice(0);
          this.deptList = res;
        });
    },
    getClass(deptCode) {
      this.axios
        .get(`/sys/class/getDepartmentsClassByLogin/${deptCode}`)
        .then(res => {
          this.classList = res;
        });
    },
    clearSchool() {
			this.schoolCodeNum="";//存储学校CODE
      this.clearDept()
      if (this.targetObj)
        this[this.targetObj].schoolCode = ''
      else
        this.updateSchoolCode('')
    },
    clearDept() {
      this.clearClass()
      this.deptList.splice(0)
      if (this.targetObj)
				this[this.targetObj].deptCode = ''
			else this.updateDeptCode('')
    },
    clearClass() {
      // debugger
      if (this.targetObj)
        this[this.targetObj].classCode = '';
      else this.updateClassCode('')
      this.classList.splice(0)
    },
  },
}
